

<extend name="./Application/Admin/View/layout.html"/>
<block name="content">


            <!-- start: Content -->
            <div id="content" class="span10">


            <ul class="breadcrumb">
                <li>
                    <i class="icon-home"></i>
                    <a href="index.html">后台</a>
                    <i class="icon-angle-right"></i>
                </li>
                <li>
                    <i class="icon-edit"></i>
                    <a href="#">商品添加</a>
                </li>
            </ul>

            <div class="row-fluid sortable">
                <div class="box span12">
                    <div class="box-header" data-original-title>
                        <h2><i class="halflings-icon white edit"></i><span class="break"></span>商品添加</h2>
                        <div class="box-icon">
                            <a href="#" class="btn-setting"><i class="halflings-icon white wrench"></i></a>
                            <a href="#" class="btn-minimize"><i class="halflings-icon white chevron-up"></i></a>
                            <a href="#" class="btn-close"><i class="halflings-icon white remove"></i></a>
                        </div>
                    </div>
                    <div class="box-content">
                        <form class="form-horizontal" enctype="multipart/form-data" id="signupfrom" method="post" action="">
                          <fieldset>
                            <div class="control-group">
                              <label class="control-label" for="typeahead">商品名称 </label>
                              <div class="controls">
                                <input type="text" id="b_name" name="goods_name" class="span2 typeahead"   data-provide="typeahead" data-items="4" >
                                <span></span>
                              </div>
                            </div>
                            <div class="control-group">
                              <label class="control-label" for="typeahead">商品编号 </label>
                              <div class="controls">
                                <input type="text" disabled="disabled" id="goods_no" name="goods_no" class="span2 typeahead"   data-provide="typeahead" data-items="4" >
                                <span></span>
                              </div>
                            </div>
                            <div class="control-group">
                              <label class="control-label" for="fileInput">图片上传</label>
                              <div class="controls">
                              <input class="input-file uniform_on" name="img" id="fileInput" type="file">
                              </div>
                            </div>
                            <div class="control-group">
                              <label class="control-label" for="typeahead">市场价 </label>
                              <div class="controls">
                                <input type="text" id="b_name" name="marke_price" class="span2 typeahead"   data-provide="typeahead" data-items="4" >
                                <span></span>
                              </div>
                            </div>
                            <div class="control-group">
                              <label class="control-label" for="typeahead">本店价 </label>
                              <div class="controls">
                                <input type="text" id="b_name" name="shop_price" class="span2 typeahead"   data-provide="typeahead" data-items="4" >
                                <span></span>
                              </div>
                            </div>
                              <div class="control-group">
                                <label class="control-label"  for="selectError3">分类</label>
                                <div class="controls">
                                  <select name="cate_id" id="selectError3">
                                  <option value="0">请选择分类类型</option>
                                    <foreach name="cate_list" item="v">
                                    <option value="{$v.id}">{$v.name}</option>
                                    </foreach>
                                  </select>
                                </div>
                              </div>
                              <div class="control-group">
                                <label class="control-label"  for="selectError3">品牌</label>
                                <div class="controls">
                                  <select name="brand_id" id="selectError3">
                                  <option value="0">请选择品牌类型</option>
                                    <foreach name="brand_list" item="v">
                                    <option value="{$v.id}">{$v.name}</option>
                                    </foreach>
                                  </select>
                                </div>
                              </div>
                              <div class="control-group">
                                <label class="control-label"  for="selectError3">商品类型</label>
                                <div class="controls">
                                  <select name="pid" id="selectError3" class="spec_item">
                                  <option value="0">请选择商品类型</option>
                                    <foreach name="goods_type" item="v">
                                    <option value="{$v.id}">{$v.name}</option>
                                    </foreach>
                                  </select>
                                </div>
                              </div>
                              <div class="control-group">
                                <label class="control-label">上架</label>
                                <div class="controls">
                                  <label class="radio">
                                    <input type="radio" name="is_down" value="1" id="optionsRadios1"  checked="">
                                    是
                                  </label>
                                  <label class="radio">
                                    <input type="radio" name="is_down" value="0" id="optionsRadios2" >
                                    否
                                  </label>
                                </div>
                              </div>
                              <div class="control-group">
                                <label class="control-label">新品</label>
                                <div class="controls">
                                  <label class="radio">
                                    <input type="radio" name="is_new" value="1" id="optionsRadios1"  checked="">
                                    是
                                  </label>
                                  <label class="radio">
                                    <input type="radio" name="is_new" value="0" id="optionsRadios2" >
                                    否
                                  </label>
                                </div>
                              </div>
                              <div class="control-group">
                                <label class="control-label">热销</label>
                                <div class="controls">
                                  <label class="radio">
                                    <input type="radio" name="is_hot" value="1" id="optionsRadios1"  checked="">
                                    是
                                  </label>
                                  <label class="radio">
                                    <input type="radio" name="is_hot" value="0" id="optionsRadios2" >
                                    否
                                  </label>
                                </div>
                              </div>
                              <div class="control-group" >
                              <label class="control-label">商品规格项</label>
                              </div>
                               <div id="item_sel">
                               <!--<foreach name="spec_list" key="k" item="v" >
                                <div class="control-group" >
                                 <label class="control-label">{$v.spec_name}</label>
                                  <foreach name="spec_item_list" key="ks" item="vs" >
                                  <if condition="$v['id'] eq $vs['spec_id']">
                                  <div class="box black span2" onTablet="span6" onDesktop="span4">
                                    <div class="box-header">
                                      <h2>{$vs.name}</h2>
                                      <div class="box-icon">
                                        <a href="#" class="btn-minimize"><i class="halflings-icon white chevron-down" fled="0"></i></a>
                                      </div>
                                    </div>
                                    <div class="box-content" style="display: none;">
                                      <ul class="dashboard-list metro">
                                        <li>
                                          <input type="text" name="spec_item_id" value="" class="span12 spec_inp">
                                        </li>
                                      </ul>
                                    </div>
                                  </div>
                                  </if>
                                  </foreach>

                                </div>
                                </foreach>
                                <script id="editor" type="text/plain" style="width:1024px;height:500px;"></script>-->
                              </div>
                              <div class="control-group" style="margin-left:170px" >
                                <button type="button" id="button" class="btn btn-primary">规格录入</button>
                              </div>
                              <div class="control-group" id="item_tab" style="margin-left:175px" >
                                <!-- <div class="box-content">
                                  <table class="table table-striped table-bordered bootstrap-datatable ">
                                    <thead>
                                        <tr>
                                            <th>id</th>
                                            <th>名称</th>
                                            <th>状态</th>
                                            <th>权限</th>
                                            <th>操作</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                      <tr>
                                          <td></td>
                                          <td></td>
                                          <td></td>
                                          <td></td>
                                          <td class="center">
                                              <a class="btn btn-danger" href="#">
                                                  <i class="halflings-icon white trash"></i>
                                              </a>
                                          </td>
                                      </tr>
                                    </tbody>
                                  </table>
                                </div> -->
                              </div>
                              <div class="control-group" style="margin-left:175px ;" >
                               <script id="editor" name="desc" type="text/plain" style="width:1024px;height:500px;"></script>
                               </div>
                            <div class="form-actions">
                              <button type="submit" class="btn btn-primary">保存</button>
                              <button type="reset" class="btn">清空</button>
                            </div>
                          </fieldset>
                        </form>

                    </div>
                </div><!--/span-->

            </div><!--/row-->
            <div class="row-fluid">
      </div>




    </div><!--/.fluid-container-->

            <!-- end: Content -->
</block>
<block name="js">
    <script type="text/javascript" charset="utf-8" src="__EDIT__ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="__EDIT__ueditor.all.min.js"> </script>
    <!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
    <!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
    <script type="text/javascript" charset="utf-8" src="__EDIT__lang/zh-cn/zh-cn.js"></script>
    <script src="__ADMIN__js/jquery.validate.min.js"></script>
    <script type="text/javascript">

      //实例化编辑器
      //建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
      var ue = UE.getEditor('editor');


      function isFocus(e){
          alert(UE.getEditor('editor').isFocus());
          UE.dom.domUtils.preventDefault(e)
      }
      function setblur(e){
          UE.getEditor('editor').blur();
          UE.dom.domUtils.preventDefault(e)
      }
      function insertHtml() {
          var value = prompt('插入html代码', '');
          UE.getEditor('editor').execCommand('insertHtml', value)
      }
      function createEditor() {
          enableBtn();
          UE.getEditor('editor');
      }
      function getAllHtml() {
          alert(UE.getEditor('editor').getAllHtml())
      }
      function getContent() {
          var arr = [];
          arr.push("使用editor.getContent()方法可以获得编辑器的内容");
          arr.push("内容为：");
          arr.push(UE.getEditor('editor').getContent());
          alert(arr.join("\n"));
      }
      function getPlainTxt() {
          var arr = [];
          arr.push("使用editor.getPlainTxt()方法可以获得编辑器的带格式的纯文本内容");
          arr.push("内容为：");
          arr.push(UE.getEditor('editor').getPlainTxt());
          alert(arr.join('\n'))
      }
      function setContent(isAppendTo) {
          var arr = [];
          arr.push("使用editor.setContent('欢迎使用ueditor')方法可以设置编辑器的内容");
          UE.getEditor('editor').setContent('欢迎使用ueditor', isAppendTo);
          alert(arr.join("\n"));
      }
      function setDisabled() {
          UE.getEditor('editor').setDisabled('fullscreen');
          disableBtn("enable");
      }

      function setEnabled() {
          UE.getEditor('editor').setEnabled();
          enableBtn();
      }

      function getText() {
          //当你点击按钮时编辑区域已经失去了焦点，如果直接用getText将不会得到内容，所以要在选回来，然后取得内容
          var range = UE.getEditor('editor').selection.getRange();
          range.select();
          var txt = UE.getEditor('editor').selection.getText();
          alert(txt)
      }

      function getContentTxt() {
          var arr = [];
          arr.push("使用editor.getContentTxt()方法可以获得编辑器的纯文本内容");
          arr.push("编辑器的纯文本内容为：");
          arr.push(UE.getEditor('editor').getContentTxt());
          alert(arr.join("\n"));
      }
      function hasContent() {
          var arr = [];
          arr.push("使用editor.hasContents()方法判断编辑器里是否有内容");
          arr.push("判断结果为：");
          arr.push(UE.getEditor('editor').hasContents());
          alert(arr.join("\n"));
      }
      function setFocus() {
          UE.getEditor('editor').focus();
      }
      function deleteEditor() {
          disableBtn();
          UE.getEditor('editor').destroy();
      }
      function disableBtn(str) {
          var div = document.getElementById('btns');
          var btns = UE.dom.domUtils.getElementsByTagName(div, "button");
          for (var i = 0, btn; btn = btns[i++];) {
              if (btn.id == str) {
                  UE.dom.domUtils.removeAttributes(btn, ["disabled"]);
              } else {
                  btn.setAttribute("disabled", "true");
              }
          }
      }
      function enableBtn() {
          var div = document.getElementById('btns');
          var btns = UE.dom.domUtils.getElementsByTagName(div, "button");
          for (var i = 0, btn; btn = btns[i++];) {
              UE.dom.domUtils.removeAttributes(btn, ["disabled"]);
          }
      }

      function getLocalData () {
          alert(UE.getEditor('editor').execCommand( "getlocaldata" ));
      }

      function clearLocalData () {
          UE.getEditor('editor').execCommand( "clearlocaldata" );
          alert("已清空草稿箱")
      }
    </script>
    <script type="text/javascript">
      $(function(){
        $('#button').click(function(event) {
          //抓取价格
          var _total_price=0;//规格总价格
          var _spec_desc='';//规格描述
          var _stock=0;//库存数量
          var _spec_id='';//规格规则id
          var spec_len=$('.spec').length;//获取完整规格数
          _stock=parseInt($('.stock').val());
          var price= $('.spec input[fled="1"]');
          if(isNaN(_stock)){
            alert('请输入正确的库存数量');
            return false;
          }
          if(spec_len!=price.length || _stock<=0){
            alert('请将录入信息填写完整');
            return false;
          }
          price.each(function(i,obj){
              _total_price+=parseInt($(obj).val());//规格价格
              _spec_desc+=$(obj).attr('spec-name')+'；';//规格描述
              _spec_id+='_'+$(obj).attr('spec-id');//规格规则
          })
           $.ajax({
            type:'post',
            url:'{:U("Admin/ajax/append_spec")}',
            data:{
              'spec_price':_total_price,
              'spec_desc':_spec_desc,
              'num':_stock,
              'spec_rule':_spec_id
            },
            dataType:'json',
            success:function(e){
              var html='';
              html+='<div class="box-content">';
              html+='<table class="table table-striped table-bordered bootstrap-datatable ">';
              html+='<thead>';
              html+='<tr>';
              html+='<th>规格规则id</th>';
              html+='<th>规格总价</th>';
              html+='<th>库存</th>';
              html+='<th>规格描述</th>';
              html+='<th>操作</th>';
              html+='</tr>';
              html+='</thead>';
              html+='<tbody>';
              for(i in e){
                html+='<tr>';
                html+='<td>'+e[i].spec_rule+'</td>';
                html+='<td>'+e[i].spec_price+'</td>';
                html+='<td>'+e[i].num+'</td>';
                html+='<td>'+e[i].spec_desc+'</td>';
                html+='<td class="center">';
                html+='<a class="btn btn-danger" href="#">';
                html+='<i class="halflings-icon white trash"></i>';
                html+='</a>';
                html+='</td>';
                html+='</tr>';
              }
              html+='</tbody>';
              html+='</table>';
              html+='</div>';
              $('#item_tab').html(html);
            },
          });
        });
        $('.spec_item').change(function(){

          var id=$(this).val();
          $('#item_sel').css({"display":"block" });
          $.ajax({
            type:'get',
            url:'{:U("Admin/ajax/getSpec")}',
            data:{
              'id':id,
            },
            dataType:'json',
            success:function(e){
              var html='';
              for(i in e){
                html+='<div class="control-group spec" style="margin-left:50px" >';
                html+='<label class="control-label">'+e[i].spec_name+'</label>';

                for(j in e[i]['spec_item']){
                  if(e[i]['id'] == e[i]['spec_item'][j]['spec_id']){
                    html+='<div class="box black span2" onTablet="span6" onDesktop="span4">';
                    html+='<div class="box-header">';
                    html+='<h2>'+e[i]['spec_item'][j]['name']+'</h2>';
                    html+='<div class="box-icon">';
                    html+='<a  class="btn-minimize"><i class="halflings-icon white chevron-down" fled="0"></i></a>';
                    html+='</div>';
                    html+='</div>';
                    html+='<div class="box-content" style="display: none;">';
                    html+='<ul class="dashboard-list metro">';
                    html+='<li>';
                    var desc=e[i].spec_name+'：'+e[i]['spec_item'][j]['name'];
                    html+='<input type="text" name="price" spec-id='+e[i]['spec_item'][j]['id']+' spec-name="'+desc+'" fled="0" value="" class="span12 spec_inp">';
                    html+='</li>';
                    html+='</ul>';
                    html+='</div>';
                    html+='</div>';
                  }
                }
                html+='</div>';

              }
                    html+='<div class="control-group" style="margin-left:50px">';
                    html+='<label class="control-label" for="typeahead">库存 </label>';
                    html+='<div class="controls">';
                    html+='<input style="margin-left:20px" type="text" id="stock" name="stock" class="span2 typeahead stock"   data-provide="typeahead" data-items="4" placeholder="请输入规格库存" >';
                    html+='<span></span>';
                    html+='</div>';
                    html+='</div>';
              $('#item_sel').html(html);
              $('.halflings-icon').click(function(event) {

                var a=$(this).attr('fled');
                if(a==0){

                  $(this).attr('fled','1');
                  $(this).parent().parent().parent().parent().find('input').attr('fled','1');
                  $(this).parent().parent().parent().parent().find('.box-content').css({"display":"block" });
                  $(this).parent().parent().parent().parent().siblings().find('input').attr('fled','0');
                  $(this).parent().parent().parent().parent().siblings().find('i').removeClass('chevron-up');
                  $(this).parent().parent().parent().parent().siblings().find('.box-content').css({"display":"none" });
                  $(this).parent().parent().parent().parent().siblings().find('input').val('');
                  $(this).parent().parent().parent().parent().siblings().find('i').addClass('chevron-down');
                  $(this).parent().parent().parent().parent().siblings().find('i').attr('fled','0');
                }else{
                  $(this).parent().parent().parent().parent().find('input').attr('fled','0');
                  $(this).parent().parent().parent().parent().find('.box-content').css({"display":"none" });
                  $(this).attr('fled','0');
                }
              });
              },
          })
        })

        // $('#item_sel').on('click','.halflings-icon',function(event) {

        //   var a=$(this).attr('fled');
        //   if(a==0){

        //     $(this).attr('fled','1');
        //     $(this).parent().parent().parent().parent().find('input').attr('fled','1');
        //     $(this).parent().parent().parent().parent().find('.box-content').css({"display":"block" });
        //     $(this).parent().parent().parent().parent().siblings().find('input').attr('fled','0');
        //     $(this).parent().parent().parent().parent().siblings().find('i').removeClass('chevron-up');
        //     $(this).parent().parent().parent().parent().siblings().find('.box-content').css({"display":"none" });
        //     $(this).parent().parent().parent().parent().siblings().find('input').val('');
        //     $(this).parent().parent().parent().parent().siblings().find('i').addClass('chevron-down');
        //     $(this).parent().parent().parent().parent().siblings().find('i').attr('fled','0');
        //   }else{
        //     $(this).parent().parent().parent().parent().find('input').attr('fled','0');
        //     $(this).parent().parent().parent().parent().find('.box-content').css({"display":"none" });
        //     $(this).attr('fled','0');
        //   }
        // });
      })
    </script>
</block>